package com.aliyun.heiyu.powermaster.server.rbac.utils;

import com.aliyun.heiyu.common.util.StringUtil;

import java.util.regex.Pattern;

/**
 * @Description ip工具类
 * @Author shun.zhang
 * @Date 2020/11/2 11:07
 **/
public class IpUtils {
    public static boolean regIp(String ip){
        try {
            if(StringUtil.isEmpty(ip)){
                return false;
            }
            String ipReg = "^(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|[1-9])\\."
                + "(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\."
                + "(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\."
                + "(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)$";
            Pattern ipPattern = Pattern.compile(ipReg);
            return ipPattern.matcher(ip).matches();
        }catch (Exception e){
            return false;
        }

    }
}
